﻿/*********************************************************************************
 * Copyright(c)  	2012 @kaleyroy
 * 创建日期：		2012-01-18 23:50:23
 * 文 件 名：		InvalidParameterException.cs 
 * CLR 版本: 		4.0.30319.239 
 * 创 建 者：		@kaleyroy 
 * 电子邮箱:		kaleyroy@gmail.com
**********************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using log4net;

/// <summary>
/// 
/// 修改记录:
///	
/// </summary>
namespace USS.Generic.Logging
{
    /// <summary>
    /// 日志管理器对象
    /// </summary>
    public class Loggers
    {
        /// <summary>
        /// 信息日志同步锁对象
        /// </summary>
        private static object infoSynLock = new object();

        /// <summary>
        /// 错误日志同步锁对象
        /// </summary>
        private static object errorSynLock = new object();

        /// <summary>
        /// 信息日志实例对象
        /// </summary>
        private static ILog infoLog = null;

        /// <summary>
        /// 错误日志实例对象
        /// </summary>
        private static ILog errorLog = null;

        /// <summary>
        /// 获取信息日志对象
        /// </summary>
        public static ILog InfoLog
        {
            get
            {
                try
                {
                    if (null == infoLog)
                        lock (infoSynLock)
                            if (null == infoLog)
                              infoLog =  LogManager.GetLogger("infoLogger");                        
                    return infoLog;
                }
                catch (Exception ex)
                {
                    throw new ApplicationException(string.Format("获取信息日志对象失败,{0}!", ex.Message));
                }
            }
        }

        /// <summary>
        /// 获取错误日志对象
        /// </summary>
        public static ILog ErrorLog
        {
            get
            {
                try
                {
                    if(null == errorLog)
                        lock(errorSynLock)
                            if(null == errorLog)
                                errorLog = LogManager.GetLogger("errorLogger");
                    return errorLog;
                }
                catch (Exception ex)
                {
                    throw new ApplicationException(string.Format("获取错误日志对象失败,{0}!", ex.Message));
                }
            }
        }

        /// <summary>
        ///  配置日志记录器
        /// </summary>
        public static void ConfigLoggers()
        {
            log4net.Config.XmlConfigurator.Configure();
        }
    }
}
